package com.greatmay.webapp.action.portal;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

import com.greatmay.model.Express;
import com.greatmay.model.Recommendation;
import com.greatmay.service.ExpressService;
import com.greatmay.service.RecommendationService;


@Results({
    @Result(name="success", type="redirectAction", params = {"actionName" , "index"})
})
@Namespace("rest")
public class IndexAction{

	private ExpressService expressService;
	private RecommendationService recommendationService;
	private List<Express> expresses;
	private List<Recommendation> recommendations;
	private long id;

    public void setExpressService(ExpressService expressService) {
        this.expressService = expressService;
    }
    
    public void setRecommendationService(RecommendationService recommendationService) {
    	this.recommendationService = recommendationService;
    }
    
	public HttpHeaders index() {
		expresses = expressService.getAll();
        return new DefaultHttpHeaders("index")
        .disableCaching();
	}

	public HttpHeaders show() {
		recommendations = recommendationService.getAll();
		String query = "category is " + Recommendation.Type.values()[(int)id];
		recommendations = recommendationService.search(query, Recommendation.class);
        return new DefaultHttpHeaders("show")
        .disableCaching();
	}
	
	public List<Express> getExpresses() {
		return expresses;
	}

	public void setExpresses(List<Express> expresses) {
		this.expresses = expresses;
	}

	public List<Recommendation> getRecommendations() {
		return recommendations;
	}

	public void setRecommendations(List<Recommendation> recommendations) {
		this.recommendations = recommendations;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

}
